#!/bin/bash

set -e

NB_FLUID_CORES=3
NB_SOLID_CORES=3

./Allclean

. $WM_PROJECT_DIR/bin/tools/RunFunctions

cp fluid/constant/preCICE.xml solid/constant/
cp fluid/system/decomposeParDict solid/system/
cp fluid/constant/fsi.yaml solid/constant/

cd fluid
runApplication blockMesh
runApplication renumberMesh -overwrite
runApplication checkMesh
runApplication decomposePar
cd -

cd solid
runApplication blockMesh
runApplication renumberMesh -overwrite
runApplication checkMesh
runApplication decomposePar
cd -

cd solid
mpirun -np $NB_SOLID_CORES --allow-run-as-root fsiSolidFoam -parallel > log.fsiSolidFoam 2>&1 &
cd -

cd fluid
mpirun -np $NB_FLUID_CORES --allow-run-as-root fsiFluidFoam -parallel > log.fsiFluidFoam 2>&1

wait

runApplication reconstructPar
cd ../solid
runApplication reconstructPar
